package com.example.lcode.backtrack;

public class Question526 {

    int res = 0;

    public int countArrangement(int n) {
        boolean []sign = new boolean[n + 1];
        int count = 1;
        countArrangement(n, sign, count);
        return res;
    }

    private void countArrangement(int n, boolean[] sign, int count) {
        if (count - 1 == n) {
            res ++;
            return;
        }
        for (int i = 1; i <= n; i++) {
            if ((count % i == 0 || i % count == 0) && !sign[i]) {
                sign[i] = true;
                countArrangement(n, sign, count + 1);
                sign[i] = false;
            }
        }
    }


    public static void main(String[] args) {
        Question526 question526 = new Question526();
        int i = question526.countArrangement(1);
        System.out.println(i);
    }

}
